package com.lzx.musiclib.utils

import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import com.lzx.starrysky.SongInfo


/**
 * @ClassName: MusicUtil
 * @Description: java类作用描述
 * @Author: zdl
 * @Date: 2021/10/12 13:35
 */
class MusicUtil {
    //获取专辑封面的UI
    private val albumArtUri = Uri.parse("content://media/external/audio/albumart")

    val songList = mutableListOf<SongInfo>()
    fun getMp3InfoList(context: Context): MutableList<SongInfo> {
        songList.clear()
        val cursor: Cursor = context.contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null)
        while (cursor.moveToNext()) {
            val url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA))
            val title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE))
            val artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST))
            val duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION))
            val id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID))
//            val album = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID))
//            val album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART))
            val mp3Info = SongInfo(id.toString(), url, title, artist, duration = duration)
            songList.add(mp3Info)
        }

        return songList
    }

}